package com.myway.dto.flight;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class DTOConnectingFlightRoute implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long id;
	private String airlineCode;
	private String departurePort;
	private String arrivalPort;
	private List<DTOConnectingFlightPort> portList;
	private String portCode;


	public DTOConnectingFlightRoute() {
		super();
		portList = new ArrayList<DTOConnectingFlightPort>();
	}

	@Override
	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("[").append(id).append("] ");
		buf.append(airlineCode).append(" ");
		buf.append(departurePort);
		for (DTOConnectingFlightPort port : portList) {
			buf.append("-").append(port.getAirportCode());
		}
		buf.append("-").append(arrivalPort);
		
		return buf.toString();
	}
	
	/**
	 * Add a connecting airport to this route. The sequence of adding is important.
	 * 
	 * @param connectingPort
	 * @param minLayover
	 *            Minimum lay-over time in minute
	 * @param maxLayover
	 *            Maximum lay-over time in minute
	 * @return The sequence of which the given connecting airport is added to the route.
	 */
	public int addPort(String connectingPort, int minLayover, int maxLayover) {
		DTOConnectingFlightPort port = new DTOConnectingFlightPort(this);
		port.setAirportCode(connectingPort);
		port.setMinLayover(minLayover);
		port.setMaxLayover(maxLayover);

		// Determine the sequence of the connecting airport to be added.
		int sequence = portList.size() + 1;
		port.setSequence(sequence);
		
		// Add to port list
		portList.add(port);
		
		return sequence;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getAirlineCode() {
		return airlineCode;
	}

	public void setAirlineCode(String airlineCode) {
		this.airlineCode = airlineCode;
	}
	
	public String getDeparturePort() {
		return departurePort;
	}

	public void setDeparturePort(String departurePort) {
		this.departurePort = departurePort;
	}

	public String getArrivalPort() {
		return arrivalPort;
	}

	public void setArrivalPort(String arrivalPort) {
		this.arrivalPort = arrivalPort;
	}

	public List<DTOConnectingFlightPort> getPortList() {
		return portList;
	}

	public void setPortList(List<DTOConnectingFlightPort> portList) {
		this.portList = portList;
	}
	
	public String getPortCode() {
		return portCode;
	}

	public void setPortCode(String portCode) {
		this.portCode = portCode;
	}
}
